var t, a = getApp(), s = require("../../../mymap/qqmap-wx-jssdk.min.js"), e = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ e ],
    data: {
        language: "",
        height: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        address: "",
        suggestionshow: !1,
        suggestion: [],
        classificationshow: !1,
        Locationshow: !1,
        commodityTitle: "",
        addgoodslistshow: !1,
        goodsdata: "",
        storeshow: !1,
        storedata: "",
        protocolshow: !1,
        photosize: 4194304,
        uploadUrl: "upload.uploadPic",
        catelist: [],
        catname: "",
        goodslistData: [],
        goodsisLoadMore: !0,
        goodsPage: 1,
        goodsTotal: 0,
        selectgoodsData: {},
        storelistData: [],
        storePage: 1,
        storeTotal: 0,
        storeisLoadMore: !0,
        selectstoreData: {},
        imgData: [],
        releasetitle: "",
        releasecontents: "",
        catid: "",
        releaseaddress: "",
        releasecity: "",
        releaselat: "",
        releaselnt: "",
        goodsId: "",
        storeId: "",
        checked: !0,
        agreementcontent: "",
        stickid: "",
        audio_open: 0,
        audioPath: [],
        audioList: []
    },
    onLoad: function(e) {
        var o = this;
        a.globalData.qqmapkey ? t = new s({
            key: a.globalData.qqmapkey
        }) : a._getTemplate().then(function(e) {
            t = new s({
                key: a.globalData.qqmapkey
            });
        }), e.stickid && 0 != Number(e.stickid) ? (this.setData({
            stickid: e.stickid
        }), this.getMicroCommentDetails()) : wx.navigateBack({
            delta: 1
        }), this._getLocation(function() {}), this.getAgreement(), wx.getSystemInfo({
            success: function(t) {
                o.setData({
                    height: t.windowHeight - 70
                });
            }
        });
    },
    removeImg: function(t) {
        var a = t.currentTarget.dataset.index;
        this.data.imgData.splice(a, 1), this.setData({
            imgData: this.data.imgData
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    onShareTimeline: function() {},
    getAgreement: function() {
        var t = this, s = a.getNetAddresss("plugin.micro-communities.api.trick.getAgreement");
        a._getNetWork({
            url: s,
            success: function(a) {
                var s = a.data;
                1 == s.result && t.setData({
                    agreementcontent: s.data ? s.data.value : "",
                    audio_open: s.data ? Number(s.data.audio_open) : 0
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onRead: function() {
        var t = this, s = a.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var e = a.tempFilePaths;
                wx.compressImage({
                    src: e[0],
                    quality: 60,
                    success: function(a) {
                        var e = a.tempFilePath;
                        wx.uploadFile({
                            url: s,
                            filePath: e,
                            name: "file",
                            success: function(a) {
                                var s = JSON.parse(a.data);
                                if (1 == s.result) {
                                    var e = s.data.img_url, o = t.data.imgData;
                                    o.push(e), t.setData({
                                        imgData: o
                                    });
                                } else wx.showToast({
                                    icon: "none",
                                    title: s.msg,
                                    duration: 1500
                                });
                            }
                        });
                    },
                    fail: function(t) {},
                    complete: function(t) {}
                });
            }
        });
    },
    releasetitleInp: function(t) {
        var a = t.detail.value;
        this.setData({
            releasetitle: a
        });
    },
    releasecontentsInp: function(t) {
        var a = t.detail.value;
        this.setData({
            releasecontents: a
        });
    },
    getClassification: function() {
        this.setData({
            classificationshow: !0
        }), this.getClassificationData();
    },
    getClassificationData: function() {
        var t = this, s = {}, e = a.getNetAddresss("plugin.micro-communities.api.index.getCate");
        this.data.commodityTitle && (s.cName = this.data.commodityTitle), a._getNetWork({
            url: e,
            data: s,
            success: function(a) {
                var s = a.data;
                1 == s.result ? t.setData({
                    catelist: s.data.data
                }) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getReleaseAddress: function() {
        this.address_detail = "", this.setData({
            Locationshow: !0
        });
    },
    getGoodsMessage: function() {
        this.getGoodsMessageData(), this.setData({
            addgoodslistshow: !0
        });
    },
    getStoreMessage: function() {
        this.getStoreMessageData(), this.setData({
            storeshow: !0
        });
    },
    getStoreMessageData: function() {
        var t = this, s = a.getNetAddresss("plugin.micro-communities.api.trick.getStore"), e = {};
        e.store_name = this.data.storedata, t.setData({
            storePage: 1
        }), a._getNetWork({
            url: s,
            data: e,
            success: function(a) {
                var s = a.data;
                1 == s.result ? t.setData({
                    storelistData: s.data.data,
                    storeTotal: s.data.last_page
                }) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getStoreMoreData: function() {
        var t = this;
        if (t.data.storeisLoadMore = !1, !(this.data.storePage >= this.data.storeTotal)) {
            this.data.storePage = this.data.storePage + 1;
            var s = a.getNetAddresss("plugin.micro-communities.api.trick.getStore");
            a._getNetWork({
                url: s,
                data: {
                    page: t.data.storePage,
                    store_name: t.data.storedata
                },
                success: function(a) {
                    var s = a.data;
                    if (t.data.storeisLoadMore = !0, 1 == s.result) {
                        var e = s.data.data;
                        console.log(t.data.storelistData), t.setData({
                            storelistData: t.data.storelistData.concat(e)
                        });
                    } else t.data.storePage = t.data.storePage - 1, t.data.storeisLoadMore = !1;
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    openProtocol: function() {
        this.setData({
            protocolshow: !0
        });
    },
    submitBtn: function() {
        if (this.data.releasetitle) if (this.data.releasecontents) if (this.data.catid) if (this.data.checked) {
            var t = {}, s = a.getNetAddresss("plugin.micro-communities.api.trick.publish");
            t.cat_id = this.data.catid, t.contents = this.data.releasecontents, t.address = this.data.releaseaddress, 
            t.images = this.data.imgData, t.title = this.data.releasetitle, t.goods_id = this.data.goodsId, 
            t.store_id = this.data.storeId, t.city = this.data.releasecity, t.lat = this.data.releaselat, 
            t.lng = this.data.releaselnt, t.ylat = this.data.releaselat, t.ylng = this.data.releaselnt, 
            t.tid = this.data.stickid, t.audio = this.data.audioPath, a._postNetWork({
                url: s,
                showToastIn: !1,
                data: t,
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? (wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    }), wx.reLaunch({
                        url: "/packageC/micro_communities/microIndex/microIndex"
                    })) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {}
            });
        } else wx.showToast({
            icon: "none",
            title: "请勾选用户协议",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请选择分类",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请添加正文",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请填写标题",
            duration: 1500
        });
    },
    protocolBtn: function(t) {
        var a = t.detail;
        this.setData({
            checked: a
        });
    },
    onClickLeft: function() {
        this.setData({
            classificationshow: !1
        });
    },
    onClickRight: function() {
        this.setData({
            classificationshow: !1
        });
    },
    commodityTitleClear: function() {
        this.setData({
            commodityTitle: ""
        });
    },
    commodityTitleInp: function(t) {
        var a = t.detail.value;
        this.setData({
            commodityTitle: a
        });
    },
    searchBtn: function() {
        this.getClassificationData();
    },
    selectCateId: function(t) {
        var a = t.currentTarget.dataset.id, s = t.currentTarget.dataset.name;
        this.setData({
            catid: a,
            catname: s,
            classificationshow: !1
        });
    },
    selectCateTwoId: function(t) {
        var a = t.currentTarget.dataset.id, s = t.currentTarget.dataset.name;
        this.setData({
            catid: a,
            catname: s + "/" + t.currentTarget.dataset.cname,
            classificationshow: !1
        });
    },
    onAddressLeft: function() {
        this.setData({
            Locationshow: !1,
            suggestionshow: !1,
            address_detail: ""
        });
    },
    onAddressRight: function() {
        this.setData({
            Locationshow: !1,
            suggestionshow: !1,
            address_detail: ""
        });
    },
    addressinpbtn: function(t) {
        var a = t.detail.value;
        this.addressinp(a);
    },
    addressinp: function(s) {
        var e = this;
        s ? t.getSuggestion({
            keyword: s,
            sig: a.globalData.qqmapsig,
            success: function(t) {
                for (var a = [], s = 0; s < t.data.length; s++) a.push({
                    title: t.data[s].title,
                    id: t.data[s].id,
                    addr: t.data[s].address,
                    city: t.data[s].city,
                    district: t.data[s].district,
                    latitude: t.data[s].location.lat,
                    longitude: t.data[s].location.lng
                });
                e.setData({
                    suggestion: a,
                    suggestionshow: !0
                });
            },
            fail: function(t) {
                console.error(t);
            },
            complete: function(t) {}
        }) : this.setData({
            suggestionshow: !1
        });
    },
    backfill: function(t) {
        for (var a = t.currentTarget.id, s = 0; s < this.data.suggestion.length; s++) s == a && this.setData({
            releaseaddress: this.data.suggestion[s].addr,
            releasecity: this.data.suggestion[s].city,
            releaselat: this.data.suggestion[s].latitude,
            releaselnt: this.data.suggestion[s].longitude,
            address_detail: "",
            suggestionshow: !1,
            Locationshow: !1
        });
    },
    onAddGoodsLeft: function() {
        this.setData({
            addgoodslistshow: !1
        });
    },
    onAddGoodsRight: function() {
        this.setData({
            addgoodslistshow: !1
        });
    },
    goodsdataClear: function() {
        this.setData({
            goodsdata: ""
        });
    },
    goodsdataInp: function(t) {
        var a = t.detail.value;
        this.setData({
            goodsdata: a
        });
    },
    searchGoodBtn: function() {
        this.getGoodsMessageData();
    },
    getGoodsMessageData: function() {
        var t = this, s = {};
        s.goods_name = this.data.goodsdata;
        var e = a.getNetAddresss("plugin.micro-communities.api.trick.getGoods");
        t.setData({
            goodsPage: 1
        }), a._getNetWork({
            url: e,
            data: s,
            success: function(a) {
                var s = a.data;
                1 == s.result ? t.setData({
                    goodslistData: s.data.data,
                    goodsTotal: s.data.last_page
                }) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getGoodMoreData: function() {
        var t = this;
        if (t.data.goodsisLoadMore = !1, !(this.data.goodsPage >= this.data.goodsTotal)) {
            this.data.goodsPage = this.data.goodsPage + 1;
            var s = a.getNetAddresss("plugin.micro-communities.api.trick.getGoods");
            a._getNetWork({
                url: s,
                data: {
                    page: t.data.goodsPage,
                    goods_name: t.data.goodsdata
                },
                success: function(a) {
                    var s = a.data;
                    if (t.data.goodsisLoadMore = !0, 1 == s.result) {
                        var e = s.data.data;
                        t.setData({
                            goodslistData: t.data.goodslistData.concat(e)
                        });
                    } else t.data.goodsPage = t.data.goodsPage - 1, t.data.goodsisLoadMore = !1;
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    setGoodsId: function(t) {
        var a = t.currentTarget.dataset.id;
        this.setData({
            goodsId: a
        });
        for (var s = {}, e = 0; e < this.data.goodslistData.length; e++) if (this.data.goodsId == this.data.goodslistData[e].id) {
            s.id = this.data.goodslistData[e].id, s.title = this.data.goodslistData[e].title, 
            s.thumb = this.data.goodslistData[e].thumb, s.price = this.data.goodslistData[e].price, 
            s.market_price = this.data.goodslistData[e].market_price, s.show_sales = this.data.goodslistData[e].show_sales;
            break;
        }
        this.setData({
            selectgoodsData: s,
            addgoodslistshow: !1
        });
    },
    storedataClear: function() {
        this.setData({
            storedata: ""
        });
    },
    storedataInp: function(t) {
        var a = t.detail.value;
        this.setData({
            storedata: a
        });
    },
    searchStoreBtn: function() {
        this.getStoreMessageData();
    },
    setStoreId: function(t) {
        var a = t.currentTarget.dataset.id;
        this.setData({
            storeId: a
        });
        for (var s = {}, e = 0; e < this.data.storelistData.length; e++) if (this.data.storeId == this.data.storelistData[e].id) {
            s.id = this.data.storelistData[e].id, s.thumb = this.data.storelistData[e].thumb, 
            s.store_name = this.data.storelistData[e].store_name, s.address = this.data.storelistData[e].address;
            break;
        }
        this.setData({
            selectstoreData: s,
            storeshow: !1
        });
    },
    protocolLeft: function() {
        this.setData({
            protocolshow: !1
        });
    },
    onStoreLeft: function() {
        this.setData({
            storeshow: !1
        });
    },
    onStoreRight: function() {
        this.setData({
            storeshow: !1
        });
    },
    getMicroCommentDetails: function() {
        var t = this, s = a.getNetAddresss("plugin.micro-communities.api.trick.getStrickDetail"), e = {
            tid: this.data.stickid
        };
        a._postNetWork({
            url: s,
            showToastIn: !1,
            data: e,
            success: function(a) {
                var s = a.data;
                if (1 == s.result) {
                    t.setData({
                        catid: s.data.cat_id,
                        catname: s.data.cat_name,
                        releasecontents: s.data.contents,
                        releaseaddress: s.data.address
                    });
                    for (var e = s.data.has_many_image, o = t.data.imgData, i = 0; i < e.length; i++) o.push(e[i].url);
                    t.setData({
                        imgData: o,
                        releasetitle: s.data.title,
                        goodsId: s.data.goods_id,
                        storeId: s.data.store_id,
                        releasecity: s.data.city,
                        releaselat: s.data.ylat,
                        releaselnt: s.data.ylng,
                        audioList: s.data.audio_src,
                        audioPath: s.data.audio
                    });
                    var d = s.data.has_one_goods;
                    d && t.setData({
                        "selectgoodsData.id": d.id,
                        "selectgoodsData.title": d.title,
                        "selectgoodsData.thumb": d.thumb,
                        "selectgoodsData.price": d.price,
                        "selectgoodsData.market_price": d.market_price,
                        "selectgoodsData.show_sales": d.show_sales
                    });
                    var n = s.data.has_one_store;
                    n && t.setData({
                        "selectstoreData.id": n.id,
                        "selectstoreData.thumb": n.thumb,
                        "selectstoreData.store_name": n.store_name,
                        "selectstoreData.address": n.address
                    });
                } else wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    updataAudio: function(t) {
        console.log(t.detail), this.data.audioPath.push({
            file: t.detail.img,
            duration: t.detail.duration || 0
        }), this.data.audioList.push({
            file: t.detail.img_url,
            duration: t.detail.duration || 0
        }), this.setData({
            audioList: this.data.audioList
        });
    },
    delAudio: function(t) {
        var a = t.currentTarget.dataset.index, s = this;
        wx.showModal({
            title: "提示",
            content: "确定要删除该音频?",
            success: function(t) {
                t.confirm && (s.data.audioPath.splice(a, 1), s.data.audioList.splice(a, 1), s.setData({
                    audioList: s.data.audioList
                }));
            }
        });
    }
});